<h2>{{ text_instruction }}</h2>
<p><b>{{ text_description }}</b></p>
<div class="well well-sm">
  <p>{{ bank }}</p>
  <p>{{ text_payment }}</p>
</div>
<div class="buttons">
  <div class="pull-right">
    <input type="button" value="{{ button_confirm }}" id="button-confirm" data-loading-text="{{ text_loading }}" class="btn btn-primary" />
  </div>
</div>
<script type="text/javascript"><!--
$('#button-confirm').on('click', function() {
	    $.ajax({
			url: 'index.php?route=checkout/cart/add',
			type: 'post',
			data: $('#product input[type=\'text\'], #product input[type=\'hidden\'], #product input[type=\'radio\']:checked, #product input[type=\'checkbox\']:checked, #product select, #product textarea'),
			dataType: 'json',
			beforeSend: function() {
				$('#button-cart').button('loading');
			},
			complete: function() {
				$('#button-cart').button('reset');
			},
			success: function(json) {
				$('.alert-dismissible, .text-danger').remove();
				$('.form-group').removeClass('has-error');

				if (json['error']) {
					if (json['error']['option']) {
						for (i in json['error']['option']) {
							var element = $('#input-option' + i.replace('_', '-'));

							if (element.parent().hasClass('input-group')) {
								element.parent().after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
							} else {
								element.after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
							}
						}
					}

					if (json['error']['recurring']) {
						$('select[name=\'recurring_id\']').after('<div class="text-danger">' + json['error']['recurring'] + '</div>');
					}

					// Highlight any found errors
					$('.text-danger').parent().addClass('has-error');
				}

				if (json['success']) {
				    
					
					
					
					
					$.ajax({
						url: 'index.php?route=checkout/guest/savehebing',
						type: 'post',
						data: $('#collapse-payment-address input[type=\'text\'], #collapse-payment-address input[type=\'date\'], #collapse-payment-address input[type=\'datetime-local\'], #collapse-payment-address input[type=\'time\'], #collapse-payment-address input[type=\'checkbox\']:checked, #collapse-payment-address input[type=\'radio\']:checked, #collapse-payment-address input[type=\'hidden\'], #collapse-payment-address textarea, #collapse-payment-address select'),
						dataType: 'json',
						beforeSend: function() {
							$("#button-confirm-mobile").attr('disabled',true);
							$("#button-confirm").attr('disabled',true);
						},
						complete: function() {
							$("#button-confirm-mobile").attr('disabled',false);
							$("#button-confirm").attr('disabled',false);
						},
						success: function(json) {
							
							if (json['redirect']) {
								location = json['redirect'];
							} else if (json['error']) {
								var elementnoteo='';
								for (i in json['error']) {
									var element = $('#input-payment-' + i.replace('_', '-'));
									if(!elementnoteo){
									   elementnoteo=element;
									}
									if ($(element).parent().hasClass('input-group')) {
										$(element).parent().after('<div class="text-danger">' + json['error'][i] + '</div>');
									} else {
										$(element).after('<div class="text-danger">' + json['error'][i] + '</div>');
									}
								}
								//console.log(element.attr("id"));
								window.location.hash = "#"+elementnoteo.attr("id");
								// Highlight any found errors
								$('.text-danger').parent().addClass('has-error');
							} else {
								
								
									$.ajax({
										url: 'index.php?route=checkout/confirm_he',
										dataType: 'html',
									   
										success: function(html) {
											//$('#collapse-checkout-confirm .panel-body').html(html);
											
											$.ajax({
												url: 'index.php?route=extension/payment/bank_transfer/confirm',
												dataType: 'json',
												beforeSend: function() {
													$('#button-confirm').button('loading');
												},
												complete: function() {
													$('#button-confirm').button('reset');
												},
												success: function(json) {
													if (json['redirect']) {
														location = json['redirect'];	
													}
												},
												error: function(xhr, ajaxOptions, thrownError) {
													alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
												}
											});

										},
										error: function(xhr, ajaxOptions, thrownError) {
											alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
										}
									});
									///////
								 
								
							}
						},
						error: function(xhr, ajaxOptions, thrownError) {
							alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
						}
					});
					
					
					
					
					
					
				    
				
				
				    

					//$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');

					//$('html, body').animate({ scrollTop: 0 }, 'slow');

					//$('#cart > ul').load('index.php?route=common/cart/info ul li');
				}
			},
			error: function(xhr, ajaxOptions, thrownError) {
				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
			}
		});
	
});
//--></script>
